package com.atguigu.study.controller;

import com.atguigu.study.pojo.User;
import com.atguigu.study.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/user/add")
    public boolean add(@RequestBody User user){
        return userService.save(user);
    }

    @GetMapping("/user/{id}")
    public User getById(@PathVariable("id") Integer id){
        return userService.getById(id);
    }
    @DeleteMapping("/user/{id}")
    public boolean deleteById(@PathVariable("id")Integer id){
        return userService.removeById(id);
    }

    @PutMapping("/user/update")
    public boolean update(@RequestBody User user){
        return userService.updateById(user);
    }

    @GetMapping("/user")
    public List<User> getAll(){
        return userService.list();
    }


}
